package com.scau.meetingbook.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.scau.meetingbook.service.UsersService;
import com.scau.meetingbook.pojo.Users;
import com.scau.meetingbook.vo.ResultVO;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    @PostMapping("/insertUsers")
    public ResultVO insertUsers(@RequestBody Users users) throws Exception {

        return usersService.insertUsers(users);
    }

    @GetMapping("/getUsersById")
    public ResultVO<Users> getUsersById(Integer id) throws Exception {
        return usersService.getUsersById(id);
    }

    @PutMapping("/updateUsersById")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "name", value = "用户名", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = false, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "String"),
    }

    )
    public ResultVO updateUsersById( @ApiParam(value = "查询条件")Users users) throws Exception {
        return usersService.updateUsersById(users);
    }

    @DeleteMapping("/deleteUsersById")
    public ResultVO deleteUsersById(Integer id) throws Exception {
        return usersService.deleteUsersById(id);
    }

    @PostMapping("/login")
    public ResultVO login(@RequestBody Users users) throws Exception {
        return usersService.login(users);
    }

    @PostMapping("/register")
    public ResultVO register(@RequestBody Users users) throws Exception {
        return usersService.register(users);
    }

    @PostMapping("/changeUserStatus")
    public ResultVO chanceUserStatus(Integer id, String status) throws Exception {
        return usersService.changeUserStatus(id, status);
    }

    @GetMapping("/getUsers")
    public ResultVO<Page<Users>> getUsers(Integer pageNum, Integer pageSize) {
        return usersService.getUsers(pageNum, pageSize);
    }

    @GetMapping("/getUsersByCondition")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名", required = false, dataType = "String"),
            @ApiImplicitParam(name = "companyName", value = "公司名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phoneNumber", value = "联系电话", required = false, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "用户状态", required = false, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = false, dataType = "Integer")

    })
    public ResultVO<Page<Users>> getUsersByCondition(@ApiParam(value = "用户信息") Users  users,
                                                     @RequestParam Integer pageNum,
                                                     @RequestParam Integer pageSize) {
        return usersService.getUsersByCondition(users, pageNum, pageSize);
    }
}